
let typeObj = { String: 'text',Double: 'number',Integer: 'number',Boolean: 'check',DateTime: 'datetime'}
let nodeTypeOptions = [
  {label: 'list', value: 'list'},
  {label: 'dictionary', value: 'dictionary'},
  {label: 'leaf', value: 'leaf'},
  // {label: 'node', value: 'node', disabled: true},
  // {label: 'root', value: 'root', disabled: true},
]
export default {
  nodeTypeOptions,
  fieldList(G_Locale) {
    let items = [
      {
        key: 'name',
        title: { 'zh-CN': '名称', 'en-US': 'name' }[G_Locale],
        span: 12,
        config: {
            type: 'text',
            clearable: true,
        },
        rules: [
          {
              required: true,
              trigger: 'blur',
              message: { 'zh-CN': '名称不能为空', 'en-US': 'The name cannot be empty' }[G_Locale]
          },
        ]
      },
      {
          key: 'link',
          title: { 'zh-CN': '关联模型', 'en-US': 'link model' }[G_Locale],
          span: 12,
          config: {
            type: 'pointer', pointerName: 'container', props: {type: '', prefix: 'logic'}
            // modelType: 'consumeModel'
          },
      },
      {
          key: 'nodeId',
          title: 'nodeId',
          span: 12,
          config: {
            type: 'text', readonly: true,
            // modelType: 'consumeModel'
          },
      },
      // {
      //     key: 'condition',
      //     title: { 'zh-CN': '激活条件', 'en-US': 'active condition' }[G_Locale],
      //     span: 12,
      //     config: {
      //       type: 'text',
      //       clearable: true,
      //     },
      // },
      // {
      //     key: 'creatFlag',
      //     title: { 'zh-CN': '创建实例', 'en-US': 'create instance' }[G_Locale],
      //     span: 12,
      //     config: {
      //       type: 'switch',
      //     },
      // }
      // hierUtil.hierPropertyFields.call(this)
    ]
    return items;
  },
  hierPropertyFields(G_Locale) {
    return {
      key: 'properties',
      title: { 'zh-CN': '属性', 'en-US': 'properties' }[G_Locale],
      config: {
        type: 'editTable',
        addTpl: {type: 'String'},
        showNum: false,
        columns: [
          {
            key: 'name',
            title: { 'zh-CN': '名称', 'en-US': 'name' }[G_Locale],
            elementName: 'fieldCell',
            props: { config: { type: 'text' } },
          },
          {
            key: 'type',
            title: { 'zh-CN': '类型', 'en-US': 'type' }[G_Locale],
            width: 120,
            elementName: 'fieldCell',
            changeDeleteItem: 'defaultValue',
            props: {
              config: {
                type: 'select', 
                options: [
                    {label: { 'zh-CN': '字符', 'en-US': 'String' }[G_Locale], value: 'String'},
                    {label: { 'zh-CN': '浮点', 'en-US': 'Double' }[G_Locale], value: 'Double'},
                    {label: { 'zh-CN': '整型', 'en-US': 'Integer' }[G_Locale], value: 'Integer'},
                    {label: { 'zh-CN': '布尔', 'en-US': 'Boolean' }[G_Locale], value: 'Boolean'},
                    {label: { 'zh-CN': '日期', 'en-US': 'DateTime' }[G_Locale], value: 'DateTime'}
                ]
              }
            },
          },
          {
            key: 'defaultValue',
            title: { 'zh-CN': '默认值', 'en-US': 'defaultValue' }[G_Locale],
            elementName: 'fieldCell',
            dynamicType: 'type',
            props: { config: { type: 'text' } },
          },
          {
            key: 'comments',
            title: { 'zh-CN': '备注', 'en-US': 'comments' }[G_Locale],
            elementName: 'fieldCell',
            props: { config: { type: 'text' } },
          },
          {
            key: 'operation',
            slot: 'operation',
            buttons: ['add', 'delete'],
          },
        ],
      },
    }
  },
  // 校验：某个key是否有重复
  checkName(data, key = 'name', lang) {
    let message = {}
    let errorLine = []
    data.forEach((item, index) => {
        if (item[key]) {
            let curValue = item[key];
            let arrFilter = data.filter(
                (fItem, fIndex) => fItem[key] === item[key] && index != fIndex
            )
            if (arrFilter.length > 0) {
                errorLine.push(index)
                if (message[curValue]) {
                    message[curValue].push(index + 1)
                } else {
                    message[curValue] = [index + 1]
                }
            }
        }
    })

    message = Object.keys(message).map(key => {
        return `num ${message[key].join('、')}, ${lang.sameName}`
    })
    return {
      message,
      errorLine
    };
},
}
